package logic

import (
	"User/srv/Models/mysql"
	"User/srv/internal/svc"
	"User/srv/pkg"
	"User/srv/user"
	"context"

	"github.com/zeromicro/go-zero/core/logx"
)

type UserRegisterLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewUserRegisterLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserRegisterLogic {
	return &UserRegisterLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *UserRegisterLogic) UserRegister(in *user.UserRegisterRequest) (*user.UserRegisterResponse, error) {
	// todo: add your logic here and delete this line
	var Users mysql.User
	if Users.ID != 0 {
		logx.Error("用户已存在,不允许注册")
	}
	U := mysql.User{
		Name:     in.Name,
		Password: pkg.Md5(in.Password),
	}
	err := mysql.DB.Create(&U).Error
	if err != nil {
		logx.Error("添加失败")
	}
	return &user.UserRegisterResponse{
		Id: int64(U.ID),
	}, nil
}
